package com.yz.group5.med_booking.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yz.group5.med_booking.entity.Appointment;
import com.yz.group5.med_booking.mapper.AppointmentMapper;
import com.yz.group5.med_booking.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppointmentServiceImpl
        extends ServiceImpl<AppointmentMapper, Appointment>
        implements AppointmentService {

    @Autowired
    private AppointmentMapper appointmentMapper;

    @Override
    public List<Appointment> listAllAppointments() {
        return baseMapper.selectList(null);
    }

    @Override
    public List<Appointment> findByUserId(Integer userId) {
        return appointmentMapper.findByUserId(userId);
    }

    @Override
    public boolean createAppointment(Appointment appointment) {
        // 这里可以添加预约时间冲突检查等业务逻辑
        // 例如：检查同一用户在同一时间段是否有重复预约
        return save(appointment);
    }

    @Override
    public boolean cancelAppointment(Integer appointmentId) {
        // 这里可以添加取消预约的业务限制
        // 例如：只能在预约时间前24小时取消
        return removeById(appointmentId);
    }

    @Override
    public List<Appointment> findByDepartmentId(Integer departmentId) {
        return appointmentMapper.findByDepartmentId(departmentId);
    }

    @Override
    public List<Appointment> findByDoctorId(Integer doctorId) {
        return appointmentMapper.findByDoctorId(doctorId);
    }
}
